﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestAssignDouble.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.DenseVectorTest
{
    #region Usings

    using System;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="DenseVectorExtensions.Assign(DenseVector{double},DenseVector{double})"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DenseVectorExtensions")]
    public sealed class TestAssignDouble
    {
        /// <summary>
        ///     Tests the method when source and target parameters have the same length.
        /// </summary>
        [Test]
        public void WhenSourceAndTargetHaveTheSameLength()
        {
            // Arrange
            var source = new DenseVector<double>(new double[] { 10, 20, 30 });
            var target = new DenseVector<double>(new double[] { 1, 2, 3 });

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(new double[] { 10, 20, 30 }));
        }

        /// <summary>
        ///     Tests the method when source parameter has less length than target parameter.
        /// </summary>
        [Test]
        public void WhenSourceHasLessLengthThanTarget()
        {
            // Arrange
            var source = new DenseVector<double>(new double[] { 10, 20 });
            var target = new DenseVector<double>(new double[] { 1, 2, 3 });

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(new[] { 10, 20, 3 }));
        }

        /// <summary>
        ///     Tests the method when source parameter has greater length than target parameter.
        /// </summary>
        [Test]
        public void WhenSourceHasGreaterLengthThanTarget()
        {
            // Arrange
            var source = new DenseVector<double>(new double[] { 10, 20, 30 });
            var target = new DenseVector<double>(new double[] { 1, 2 });

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(new[] { 10, 20 }));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when source parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenSourceIsNull()
        {
            // Arrange
            var target = new DenseVector<double>(3);

            // Act and Assert
            Assert.That(
                () => target.Assign(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("source"));
        }

        /// <summary>
        ///     Tests the method when target parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenTargetIsNull()
        {
            // Arrange
            var source = new DenseVector<double>(3);

            // Act and Assert
            Assert.That(
                () => DenseVectorExtensions.Assign(null, source),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("target"));
        }

#endif
    }
}